<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Notifications extends CI_Controller {

	public function index()
	{
		$this->load->model('m_notifications');
		$recordset = $this->m_notifications->get_user_id($this->session->userdata('useremail'));
		$results = $recordset->result();
		$data['userId'] = $results[0]->userId;
		
		$recordset = $this->m_notifications->get_notifications($data['userId']);
		$results = $recordset->result();
		$data['notifications'] = $results;
		
		$this->load->view('v_notifications', $data);
	}

	public function addnotification()
	{
		$this->load->model('m_notifications');
		$recordset = $this->m_notifications->get_user_id($this->session->userdata('useremail'));
		$results = $recordset->result();
		$data['userId'] = $results[0]->userId;
		
		$date = $this->input->post('date', TRUE);
		$occurance = $this->input->post('occurance', TRUE);
		$message = $this->input->post('message', TRUE);
		
		$date = explode('/', $date);
		$date = $date[2] . '-' . $date[0] . '-' . $date[1];
		$this->m_notifications->insert_notification($data['userId'], $date, $occurance, $message);
		
		$recordset = $this->m_notifications->get_notifications($data['userId']);
		$results = $recordset->result();
		$data['notifications'] = $results;
		
		$this->load->view('v_notifications', $data);
	}
	
	public function removenotification($notificationID)
	{
		$this->load->model('m_notifications');
		$recordset = $this->m_notifications->get_user_id($this->session->userdata('useremail'));
		$results = $recordset->result();
		$data['userId'] = $results[0]->userId;
		
		$this->m_notifications->delete_notification($notificationID);
		
		$recordset = $this->m_notifications->get_notifications($data['userId']);
		$results = $recordset->result();
		$data['notifications'] = $results;
		
		$this->load->view('v_notifications', $data);
	}
}

/* End of file userprofile.php */
/* Location: ./application/controllers/userprofile.php */
